package  
{
	import flash.display.Sprite;
	import flash.ui.Keyboard;
	import interfaces.IOperate;
	import morn.core.components.BitmapText;
	import morn.core.components.Clip;
	
	/**
	 * 对话提示消息
	 * @author WLDragon 2014-03-26
	 */
	public class Msg extends Sprite implements IOperate 
	{
		public function Msg()
		{
			content = new BitmapText();
			addChild(content);
			
			arrow = new Clip("png.common.clip_arrow", 1, 2);
			arrow.mouseChildren = false;
			arrow.mouseEnabled = false;
			arrow.visible = false;
			arrow.x = 290;
			arrow.y = 432;
			addChild(arrow);
			
			Lyr.ui.addChild(this);
		}
		
		static private var _instance:Msg;
		static public function get instance():Msg
		{
			return _instance ||= new Msg;
		}
		
		/* INTERFACE interfaces.IOperate */
		
		public function execute(keyCode:int):void 
		{
			switch (keyCode) 
			{
				case Keyboard.SPACE:
					okFun.apply(null,okFunArgs);
					App.timer.clearTimer(showArrow);
					arrow.visible = false;
				break;
				case Keyboard.R:
					if (cancelFun != null)
					{
						cancelFun.apply(null, cancelArgs);
						arrow.visible = false;
					}
				break;
			}
		}
		
		/**
		 * 提示文本
		 * @param	text       文本内容
		 * @param	tx         显示的位置x
		 * @param	ty         显示的位置y
		 * @param	size       文本的大小*2
		 * @param	okFun      按空格后执行回调
		 * @param   okArgs     okFun的参数
		 * @param   cancelFun  取消的回调方法
		 * @param   cancelArgs cancelFun的参数
		 */
		public function show(text:String,tx:int = 125,ty:int = 320,size:int = 12,okFun:Function = null,okArgs:Array = null,cancelFun:Function = null,cancelArgs:Array = null):void
		{
			content.leading = 10;
			content.text = text;
			content.x = tx;
			content.y = ty;
			content.realSize = size;
			
			if (okFun != null)
			{
				//显示箭头
				App.timer.doLoop(200, showArrow);
				
				//设置回调
				this.okFun = okFun;
				this.okFunArgs = okArgs;
				this.cancelFun = cancelFun;
				this.cancelArgs = cancelArgs;
				Kyb.setOperater(this);
			}
		}
		
		private function showArrow():void
		{
			arrow.visible = !arrow.visible;
		}
		
		private var okFun:Function;
		private var okFunArgs:Array;
		private var cancelFun:Function;
		private var cancelArgs:Array;
		private var content:BitmapText;
		private var arrow:Clip;
	}

}